package com.java.simple.study.juc.p7;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author zhoujunlin
 * @date 2022年08月06日 21:15
 * @desc
 */
@Slf4j(topic = "c.TestThreadPoolException")
public class TestThreadPoolException {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //excepStyle1();
        LocalDateTime now = LocalDateTime.now();
        ExecutorService pool = Executors.newFixedThreadPool(1);
        Future<Boolean> f = pool.submit(() -> {
            log.debug("task1");
            int i = 1 / 0;
            return true;
        });
        log.debug("result:{}", f.get());
    }

    private static void excepStyle1() {
        ExecutorService pool = Executors.newFixedThreadPool(1);
        pool.submit(() -> {
            try {
                log.debug("task1");
                int i = 1 / 0;
            } catch (Exception e) {
                log.error("error:", e);
            }
        });
    }

}
